﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace DuAnNH.Fd_class
{
    class ClsKetNoiCSDL
    {
        //public static SqlConnection dangnhap;
        //public static bool ketnoi(string server, string csdl, string users, string pass)
        //{
        //    try
        //    {
        //        string str = string.Format("Data Source={0};Initial Catalog={1};User ID={2};Password={3}", server, csdl, users, pass);
        //        dangnhap = new SqlConnection(str);
        //        dangnhap.Open();
        //        return true;
        //    }
        //    catch(Exception ex)
        //    {
        //        MessageBox.Show(ex.Message);
        //        return false;
        //    }
        //}
        //public static int so;
        
        public SqlConnection con;
        public bool ketnoi;
        public void ClsKetNoi()
        {
            try
            {
                string str = string.Format(@"Data Source=TINH\SQLEXPRESS;Initial Catalog=NhaHang;User ID=sa;Password=123");
                con = new SqlConnection(str);
                con.Open();
                ketnoi = true;
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                ketnoi = false;
            }
        }
        public SqlConnection cnn = new SqlConnection();
        public SqlCommand cmd = new SqlCommand();
        string st = @"Data Source=.\SQL2005; Initial Catalog=NhaHang; User id=sa; Password=123";
        
        public void KetNoiCSDL()
        {
            try
            {
                cnn.ConnectionString = st;
                cmd.Connection = cnn;
                cmd.CommandText = @"USE NhaHang; GO BACKUP DATABASE NhaHang TO DISK = 'C:\NhaHang1.Bak' WITH FORMAT, MEDIANAME = 'D_SQLServerBackups', NAME = 'Full Backup of NhaHang'; GO";
                cmd.CommandType = CommandType.Text;
                cnn.Open();
                cmd.ExecuteNonQuery();
                ketnoi = true;
                cnn.Close();
            }
            catch
            {
                ketnoi = false;
            }
        }
    }
}
